#include "EntryManager.h"


EntryManager::EntryManager(void)
{
}


EntryManager::~EntryManager(void)
{
}

Entry* EntryManager::compareEntry(Entry* initialEntry, Entry* newEntry) {
	if((initialEntry->getEntryType()) != (initialEntry->getEntryType())){
		return compareByType(initialEntry, newEntry);
	}
	else{
		if(((initialEntry->getEntryType()) == newEntry->getEntryType()) && (initialEntry->getEntryType() == "EVENT")){
			if(QDate(initialEntry->getStartDate()) != QDate(newEntry->getStartDate())){
				return compareByStartDate(initialEntry, newEntry);
			}
			else{
				if(QTime(initialEntry->getStartTime()) != QTime(newEntry->getStartTime())){
					return compareByStartTime(initialEntry, newEntry);
				}
				else{
					if((initialEntry->getName()) != (newEntry->getName())){
							return compareByName(initialEntry, newEntry);
					}
					else{
						if(QTime(initialEntry->getEndTime()) != QTime(newEntry->getEndTime())){
						return compareByEndTime(initialEntry, newEntry);
						}
						else{
							if((initialEntry->getStatus()) != (newEntry->getStatus())){
							return compareByStatus(initialEntry, newEntry);
							}
						}
					}
				}
			}
		//return new Entry();
		}
		if(((initialEntry->getEntryType()) == newEntry->getEntryType()) && (initialEntry->getEntryType() == "TASK")){
			if((initialEntry->getStatus()) != (newEntry->getStatus())){
							return compareByStatus(initialEntry, newEntry);
			}
			else{
				if(QDateTime(initialEntry->getEndDate(), initialEntry->getEndTime()) != QDateTime(newEntry->getEndDate(), newEntry->getEndTime())){
					return compareByEndDateTime(initialEntry, newEntry);
				}
				else{
					if((initialEntry->getName()) != (newEntry->getName())){
						return compareByName(initialEntry, newEntry);
					}
				}
			}
		}

	}
//return new Entry();
}
Entry* EntryManager::compareByType(Entry* initialEntry, Entry* newEntry){
	if((initialEntry->getEntryType()) < (newEntry->getEntryType())){
		return initialEntry;
	}
	else{
		return newEntry;
	}
}
Entry* EntryManager::compareByStartDate(Entry* initialEntry, Entry* newEntry){
	if(QDate(initialEntry->getStartDate()) < QDate(newEntry->getStartDate())){
		return initialEntry;
	}
	else{
		return newEntry;
	}
;}
Entry* EntryManager::compareByStartTime(Entry* initialEntry, Entry* newEntry){
	if(QTime(initialEntry->getStartTime()) < QTime(newEntry->getStartTime())){
		return initialEntry;
	}
	else{
		return newEntry;
	}
;}
Entry* EntryManager::compareByEndTime(Entry* initialEntry, Entry* newEntry){
	if(QTime(initialEntry->getEndTime()) < QTime(newEntry->getEndTime())){
		return initialEntry;
	}
	else{
		return newEntry;
	}
;}
Entry* EntryManager::compareByName(Entry* initialEntry, Entry* newEntry){
	if((initialEntry->getName()) < (newEntry->getName())){
		return initialEntry;}
	else{
		return newEntry;
	}
;}
Entry* EntryManager::compareByStatus(Entry* initialEntry, Entry* newEntry){
	if((initialEntry->getStatus()) < (newEntry->getStatus())){
		return initialEntry;
	}
	else{
		return newEntry;
	}
;}
Entry* EntryManager::compareByEndDateTime(Entry* initialEntry, Entry* newEntry){
	if(QDateTime(initialEntry->getEndDate(), initialEntry->getEndTime()) < QDateTime(newEntry->getEndDate(), newEntry->getEndTime())){
		return initialEntry;
	}
	else{
		return newEntry;
	}
}
bool EntryManager::greater(const Entry* a, const Entry* b)
{
	if (QDateTime(a->getEndDate(),a->getEndTime()) == QDateTime(b->getEndDate(), b->getEndTime()))
		return a->getName() < b->getName();

	return QDateTime(a->getEndDate(),a->getEndTime()) < QDateTime(b->getEndDate(),b->getEndTime());
}
const string EntryManager::MSG_OUTPUT= "%s due by <%s %s>";
char EntryManager::_buffer[MAX_SIZE];